<?php
/**
 * @package au2  
 * @author Jaroslaw Mezyk <j.mezyk@netcoffee.pl>
 * @copyright Jaroslaw Mezyk 2008
 * @license GPL 3
 */


/**
 * Manages variables 
 *
 * This is SINGLETON, use variables_au2::singleton() instead of creating object directly
 * 
 * @package au2
 * @copyright Jaroslaw Mezyk 2008
 * @author Jaroslaw Mezyk <j.mezyk@netcoffee.pl> 
 * @license GPL 3
 */
class variables_au2{


	/**
	 * Contains global instance / singleton pattern 
	 *
	 * @var variables_au2
	 * @access private
	 * @see singleton()
	 * @see __construct()
	 * @see __clone()
	 * @static
	 */
	private static $instance;

	/**
	 * Contains all the variable values
	 *
	 * Hash of strings
	 * 
	 * @var array
	 * @access private
	 * @see setVar()
	 */
	private $shVariables = array();



	/**
	 * Private constructor; prevents direct creation of object
	 * 
	 * @access private
	 * @return void
	 * @see singleton()
	 * @see __clone()
	 */
	private function __construct(){
	}


	/**
	 * returns singleton object
	 * 
	 * @static
	 * @access public
	 * @return variables_au2 global instance of variables_au2
	 * @see $instance
	 * @see __construct()
	 * @see __clone()
	 */
	public static function singleton(){
/*{{{*/
		if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c;
		}

		return self::$instance;
/*}}}*/
	}


	/**
	 * __clone 
	 * 
	 * @access public
	 * @return void
	 * @throws Exception - Always! Cloning not allowed
	 */
	public function __clone(){
/*{{{*/
		throw new Exception("This class implements Singleton pattern. Cloning prohibited");
/*}}}*/
	}


	/**
	 * Sets variable value
	 * 
	 * @param string $sVariableName name of the variable
	 * @param mixed $sVariableValue value of the variable
	 * @access public
	 * @return void
	 */
	public function setVar($sVariableName, $sVariableValue){
/*{{{*/
		$this -> shVariables[$sVariableName] = $sVariableValue;
/*}}}*/
	}


	/**
	 * Returns variable value or false if variable is not set
	 * 
	 * @param string $sVariableName variable name
	 * @access public
	 * @return string variable value or false if variable is not set
	 */
	public function getVar($sVariableName){
/*{{{*/
		if(isset($this -> shVariables[$sVariableName])){
			return $this -> shVariables[$sVariableName];
		}else{
			return false;
		}
/*}}}*/
	}

}

?>
